﻿Imports FairShop
Imports FairShop.Helpers
Imports Microsoft.VisualStudio.TestTools.UnitTesting

'''<summary>
'''This is a test class for BarcodeDalTest and is intended
'''to contain all BarcodeDalTest Unit Tests
'''</summary>
<TestClass()> _
Public Class TestBarcodeHelper


    Private testContextInstance As TestContext

    '''<summary>
    '''Gets or sets the test context which provides
    '''information about and functionality for the current test run.
    '''</summary>
    Public Property TestContext() As TestContext
        Get
            Return testContextInstance
        End Get
        Set(ByVal value As TestContext)
            testContextInstance = value
        End Set
    End Property

#Region "Additional test attributes"
    '
    'You can use the following additional attributes as you write your tests:
    '
    'Use ClassInitialize to run code before running the first test in the class
    '<ClassInitialize()>  _
    'Public Shared Sub MyClassInitialize(ByVal testContext As TestContext)
    'End Sub
    '
    'Use ClassCleanup to run code after all tests in a class have run
    '<ClassCleanup()>  _
    'Public Shared Sub MyClassCleanup()
    'End Sub
    '
    'Use TestInitialize to run code before running each test
    '<TestInitialize()>  _
    'Public Sub MyTestInitialize()
    'End Sub
    '
    'Use TestCleanup to run code after each test has run
    '<TestCleanup()>  _
    'Public Sub MyTestCleanup()
    'End Sub
    '
#End Region

    '''<summary>
    '''A test for CalculateChecksumDigit
    '''</summary>
    <TestMethod(), DeploymentItem("FairShop.exe")> _
    Public Sub CalculateChecksumDigitTest()
        Assert.AreEqual("7", BarcodeHelper.CalculateChecksumDigit("7351353"))
        Assert.AreEqual("1", BarcodeHelper.CalculateChecksumDigit("290000000000"))
        Assert.AreEqual("8", BarcodeHelper.CalculateChecksumDigit("290000000001"))
    End Sub

    '''<summary>
    '''A test for FixBarcode
    '''</summary>
    <TestMethod(), DeploymentItem("FairShop.exe")> _
    Public Sub FixBarcodeTest()
        Assert.AreEqual("5400161234567", BarcodeHelper.FixBarcode("05400161234567"))
        Assert.AreEqual("12*5400161234567", BarcodeHelper.FixBarcode("12*05400161234567"))
        Assert.AreEqual("5400161234567", BarcodeHelper.FixBarcode("5400161234567"))
    End Sub

    '''<summary>
    '''A test for CheckValidBarcode
    '''</summary>
    <TestMethod(), DeploymentItem("FairShop.exe")> _
    Public Sub CheckValidBarcodeTest()
        Assert.AreEqual(True, BarcodeHelper.CheckValidBarcode("5400161234567", False))
        Assert.AreEqual(True, BarcodeHelper.CheckValidBarcode("6*5400161234567", False))
        Assert.AreEqual(True, BarcodeHelper.CheckValidBarcode("12*5400161234567", False))
        Assert.AreEqual(False, BarcodeHelper.CheckValidBarcode("-12*5400161234567", False))
        Assert.AreEqual(True, BarcodeHelper.CheckValidBarcode("-12*5400161234567", True))
        Assert.AreEqual(False, BarcodeHelper.CheckValidBarcode("-12*5400161", True))
        Assert.AreEqual(False, BarcodeHelper.CheckValidBarcode("12*54001612345678", False))
        Assert.AreEqual(False, BarcodeHelper.CheckValidBarcode("-12*54001612345678", True))
    End Sub


End Class
